package com.haonan.springboot_exercise.bean.pojo;

import com.haonan.springboot_exercise.bean.Email;
import lombok.Data;

/**
 * 给前端的表单
 * 在收件箱页面要用
 * ** 邮件主题和内容有长度限制
 * @author haonan
 * @date 2021/4/17 19:47
 **/
public class ReadableMail extends Email {

    /**
     * 自定义主题、正文可视长度
     * @param email Email对象
     * @param subjLength 主题可视长度
     * @param textLength 正文可视长度
     */
    public ReadableMail(Email email, int subjLength, int textLength){
        setEmail_id(email.getEmail_id());
        setFrom(email.getFrom());
        setTo(email.getTo());
        setSent_time(email.getSent_time());
        setSubject(email.getSubject().substring(0,Math.min(email.getSubject().length(), subjLength)));
        setText(email.getText().substring(0,Math.min(email.getText().length(), textLength)));
    }

    /**
     * 默认长度
     * @param email Email对象
     */
    public ReadableMail(Email email){
        setEmail_id(email.getEmail_id());
        setFrom(email.getFrom());
        setTo(email.getTo());
        setSent_time(email.getSent_time());
        setSubject(email.getSubject().substring(0, Math.min(email.getSubject().length(), 10)));
        setText(email.getText().substring(0, Math.min(email.getText().length(), 30)));
    }

}
